﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
@section Content {
    <style>
        .panel-default {
            border-radius: 0;
            padding-top: 5px;
        }

        .panel-primary {
            border-top-width: 0;
            border-radius: 0;
            border-color: #ddd;
        }

            .panel-primary > .panel-heading {
                color: #000;
                border-color: #ddd;
                background-color: silver;
            }

        .panel-heading {
            border-radius: 0;
        }

        .nav-tabs > li > a {
            border-radius: 0;
        }
    </style>    
}
<script>
    var orderId = $.request("orderId"),
        siteId = $.request("siteId"),
        spaceId = $.request("spaceId");

    $(function () {
        if (!!orderId && !!siteId) {
            $("#OrderId").val(orderId);
            $("#SiteId").val(siteId);
            $("#SpaceId").val(spaceId);
        }

        $('#txt_res, #txt_cars, #txt_drivers').bindSelect();

        //$.ajax({
        //    url: "/OrderFlowManage/ClientOrder/GetDeptByUsersJson",
        //    data: {},
        //    dataType: "json",
        //    async: false,
        //    success: function (data) {
        //        var index = 0,
        //            depts = [],
        //            users = [];
        //        for (var i in data) {

        //            if (index == 0) {
        //                depts.push('<option selected value="' + i + '">' + i + '</option>');
        //                var items = data[i];
        //                for (var j = 0; j < items.length; j++) {
        //                    var item = items[j];
        //                    users.push('<option value="' + item.F_UserId + '">' + item.F_UserName + '</option>');
        //                }
        //            } else {
        //                depts.push('<option value="' + i + '">' + i + '</option>');
        //            }
        //            index++;
        //        }
        //        $("#txt_depts").html(depts.join('')).bindSelect();
        //        $("#txt_users").html(users.join('')).bindSelect();
        //    }
        //});

        $.ajax({
            url: "/OrderFlowManage/ClientOrder/GetTakelookAllotUserJson",
            data: {},
            dataType: "json",
            async: false,
            success: function (data) {
                if (data && data.dept && data.user) {
                    $("#txt_depts").html('<option value="' + data.dept.Value + '">' + data.dept.Text + '</option>').bindSelect();
                    $("#txt_users").html('<option value="' + data.user.Value + '">' + data.user.Text + '</option>').bindSelect();
                }
            }
        });
    });
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }

        var car = [], people = [];
        if ($("#check_car").prop("checked")) {
            car.push(JSON.stringify({ resName: $('#txt_res').val(), driverName: $('#txt_drivers').val(), carId: $("#txt_cars").val(), carName: $("#txt_cars").find(":selected").text() }));
        }
        if ($("#check_people").prop("checked")) {
            people.push(JSON.stringify({ deptName: $('#txt_depts').val(), userId: $("#txt_users").val(), userName: $("#txt_users").find(":selected").text() }));
        }
        var param = {
            Time: {
                OrderId: orderId, SiteId: siteId, SpaceId: spaceId,
                F_StartTime: $("#F_StartTime").val(),
                F_EndTime: $("#F_EndTime").val(),
            },
            Car: {
                OrderId: orderId, SiteId: siteId, SpaceId: spaceId,
                Data: car
            },
            People: {
                OrderId: orderId, SiteId: siteId, SpaceId: spaceId,
                Data: people
            }
        };
        //console.log(param);
        $.submitForm({
            url: "/OrderFlowManage/ClientOrder/SubmitPreviewForm?keyValue=" + orderId,
            param: param,
            success: function () {
                $.currentWindow().vm.takelook.initTakelook();
                $.loading(false);
            }
        });
    }
</script>

<form id="form1">
    <input type="hidden" id="OrderId" name="OrderId" value="" />
    <input type="hidden" id="SiteId" name="SiteId" value="" />
    <input type="hidden" id="SpaceId" name="SpaceId" value="" />
    <div style="padding-top: 20px;">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <span class="h5">预约时间</span>
            </div>
            <table class="form">
                <tr>
                    <th class="formTitle">开始时间：</th>
                    <td class="formValue">
                        <input id="F_StartTime" name="F_StartTime" type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker({dateFmt:'yyyy-M-d HH:mm', minDate:'%y-%M-{%d+1}', maxDate:'#F{$dp.$D(\'F_EndTime\')||\'2020-10-01\'}', readOnly:true})" placeholder="请录入开始时间" />
                    </td>
                    <th class="formTitle">结束时间：</th>
                    <td class="formValue">
                        <input id="F_EndTime" name="F_EndTime" type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker({dateFmt:'yyyy-M-d HH:mm', minDate:'#F{$dp.$D(\'F_StartTime\')}',maxDate:'2020-10-01', readOnly:true})" placeholder="请录入结束时间" />
                    </td>
                </tr>
            </table>
            <div class="panel-heading">
                <span class="h5">预约带看人</span>
            </div>
            <table class="table table-border table-hover">
                <tr>
                    <th>
                        选择
                    </th>
                    <td>
                        部门
                    </td>
                    <td>
                        陪同人员
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">
                        <input id="check_people" type="checkbox" />
                    </th>
                    <td class="formValue">
                        <select id="txt_depts" name="txt_depts" class="form-control txt_depts"></select>
                    </td>
                    <td class="formValue">
                        <select id="txt_users" name="txt_users" class="form-control txt_users"></select>
                    </td>
                </tr>
            </table>

            <div class="panel-heading">
                <span class="h5">预约车辆</span>
            </div>
            <table class="table table-border table-hover">
                <tr>
                    <th>
                        选择
                    </th>
                    <td>
                        车辆
                    </td>
                    <td>
                        车辆信息信息
                    </td>
                    <td>
                        司机
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">
                        <input id="check_car" type="checkbox" />
                    </th>
                    <td class="formValue">
                        <select id="txt_res" name="txt_res" class="form-control txt_res">
                            <option selected value="车辆">车辆</option>
                        </select>
                    </td>
                    <td class="formValue">
                        <select id="txt_cars" name="txt_cars" class="form-control txt_cars">
                            <option selected value="桑塔纳9527">桑塔纳9527</option>
                        </select>
                    </td>
                    <td class="formValue">
                        <select id="txt_drivers" name="txt_drivers" class="form-control txt_drivers">
                            <option selected value="江师傅">江师傅</option>
                        </select>
                    </td>
                </tr>
            </table>

        </div>
    </div>
</form>


